package com.zm.zmgz.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegularUtils {

    public static void main(String[] args) {
        List<String> allPath = getAllPath("/employee/employeeInformation/add/", new ArrayList<String>());
        System.out.println(allPath);
    }

    /*
    * 功能:返回path的所有父级路径
    * 如果path="/employee/employeeInformation/add"
    * 则返回 "/employee/employeeInformation","/employee"组成的集合
    * */
    public static List<String> getAllPath(String path,List<String> allPath) {
            String pattern = "(/[\\u4E00-\\u9FA5A-Za-z0-9_].+/)";
            Pattern r = Pattern.compile(pattern);
            Matcher m = r.matcher(path);
            String substring = "";
            System.out.println("当前path:"+path);
            if(m.find()) {
                 substring = m.group().substring(0, m.group().length() - 1);
                System.out.println("获取的父级path:"+substring);
                 allPath.add(substring);
            }
            if(substring.length()>0) {
                System.out.println("可能存在父级path,继续获取!");
                allPath.addAll(getAllPath(substring,allPath));
            }
            return allPath;
    }

}
